//
//  AppDelegate.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/25.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "AppDelegate.h"
#import "TabViewController.h"
#import "LoginViewController.h"
#import "RootViewController.h"
#import <Bugly/Bugly.h>
@interface AppDelegate ()

@end

@implementation AppDelegate

+ (instancetype)shared {
    return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
   
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    if ([TokenManager getUserId].length ==0) {
     LoginViewController *loginVC = [LoginViewController loadStroyboard:[LoginViewController new]];
     RootViewController * nav = [[RootViewController alloc] initWithRootViewController:loginVC];
    self.window.rootViewController = nav;
    }else{
        
        TabViewController *rootVC = [[TabViewController alloc]init];
        self.window.rootViewController = rootVC;
        
    }
    // 检测网络
    [AFNetworkingManager listenNetWorkingStatus];
    
     [self.window makeKeyAndVisible];
    
//   [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
//    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
//    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
     [Bugly startWithAppId:@"bf1198d748"];
    return YES;
}

-(void)quitApp{
    
     LoginViewController *loginVC = [LoginViewController loadStroyboard:[LoginViewController new]];
     loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
     [[self visibleViewController] presentViewController:loginVC animated:YES completion:nil];
    
}
- (UIViewController *)visibleViewController {
    UIViewController *rootViewController = self.window.rootViewController;
    return [self getVisibleViewControllerFrom:rootViewController];
}

-(UIViewController *) getVisibleViewControllerFrom:(UIViewController *) vc {
    
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self getVisibleViewControllerFrom:[((UINavigationController *) vc) visibleViewController]];
    } else if ([vc isKindOfClass:[UITabBarController class]]) {
        return [self getVisibleViewControllerFrom:[((UITabBarController *) vc) selectedViewController]];
    } else {
        if (vc.presentedViewController) {
            return [self getVisibleViewControllerFrom:vc.presentedViewController];
        } else {
            return vc;
        }
    }
}

#pragma mark - UISceneSession lifecycle





@end
